﻿/*
* Copyright (c) 2008 michiyasu wada
* http://www.seyself.com/
* 
* Distributed under The MIT License.
* [http://www.opensource.org/licenses/mit-license.php]
*/


import flash.events.Event;
import com.seyself.switches.Switch;


class com.seyself.switches.ButtonSwitch extends Switch
{
    /**
    * 選択中のボタンの動作の有無を指定します。デフォルト（false）では選択中のボタンの enabled プロパティが false に設定されます。
    */
    public var selectedEnabled:Boolean = false;
    
    public function ButtonSwitch( equal:Boolean, selectedEnabled:Boolean )
    {
        super( equal );
        this.selectedEnabled = selectedEnabled == true;
        this.addEventListener( "change" , _changeHandler );
    }
    
    public function toString():String
    {
        return "[object ButtonSwitch]";
    }
    
    //__________________________ p r i v a t e __________________________
    
    private function _changeHandler( event:Event ):Void
    {
        if( !selectedEnabled ){
            previous.enabled = true;
            previous.gotoAndStop("_up");
        }
        if( !selectedEnabled ){
            selected.enabled = false;
            selected.gotoAndStop("_disabled");
        }
    }
}
